package com.fr.web.core.chwriter;

import com.fr.base.CodeUtils;
import com.fr.base.ColumnRow;
import com.fr.base.FRContext;
import com.fr.base.Painter;
import com.fr.base.Style;
import com.fr.base.core.DateUtils;
import com.fr.base.core.html.Tag;
import com.fr.base.core.html.TextHtml;
import com.fr.base.core.json.JSONException;
import com.fr.chart.ChartPainter;
import com.fr.data.core.db.BinaryObject;
import com.fr.report.CellElement;
import com.fr.report.ReportGetter;
import com.fr.report.cellElement.CellGUIAttr;
import com.fr.report.cellElement.Formula;
import com.fr.report.cellElement.TextFormat;
import com.fr.report.cellElement.core.CellElementAttribute;
import com.fr.report.cellElement.core.CellUtils;
import com.fr.report.core.PaintUtils;
import com.fr.web.Repository;
import com.fr.web.core.CellBackgroundDimension;
import com.fr.web.core.HTMLWriterUtils;
import java.awt.Image;
import java.awt.Rectangle;
import java.sql.Blob;
import java.sql.Clob;
import java.text.DecimalFormat;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;

public class EditCellWriter extends CellHtmlWriter
{
  public EditCellWriter(Repository paramRepository, int paramInt)
  {
    super(paramRepository, paramInt);
  }

  public Tag cell2Tag(CellElement paramCellElement, ReportGetter paramReportGetter, Rectangle paramRectangle1, Rectangle paramRectangle2)
  {
    Tag localTag = null;
    try
    {
      localTag = super.cell2Tag(paramCellElement, paramReportGetter, paramRectangle1, paramRectangle2);
    }
    catch (JSONException localJSONException1)
    {
      FRContext.getLogger().log(Level.WARNING, localJSONException1.getMessage(), localJSONException1);
    }
    Object localObject1 = paramCellElement.getAttribute(CellElementAttribute.HTML_ID);
    if (localObject1 != null)
    {
      if (localObject1 instanceof ColumnRow[])
      {
        ColumnRow[] arrayOfColumnRow = (ColumnRow[])localObject1;
        this.resTag.attr("id", arrayOfColumnRow[0] + "-" + this.reportIndex + "-" + this.tableID).attr("row", "" + arrayOfColumnRow[0].getRow()).attr("col", "" + arrayOfColumnRow[0].getColumn());
        break label305:
      }
      return this.resTag;
    }
    this.resTag.attr("id", ColumnRow.valueOf(paramCellElement.getColumn(), paramCellElement.getRow()) + "-" + this.reportIndex + "-" + this.tableID).attr("row", "" + paramCellElement.getRow()).attr("col", "" + paramCellElement.getColumn());
    label305: Style localStyle = paramCellElement.getStyle();
    Object localObject2 = localStyle.getFormat();
    Object localObject3 = paramCellElement.getValue();
    if (localObject3 instanceof Formula)
    {
      this.resTag.attr("fm", ((Formula)localObject3).getContent().substring(1));
      localObject3 = dealWithValue4Formula(localObject3);
    }
    if (localObject3 != null)
    {
      if ((localObject3 instanceof Date) && (localObject2 == null))
        localObject2 = DateUtils.DATEFORMAT1;
      else if ((localObject2 == null) && (localObject3 instanceof String) && (localObject3.toString().length() > 0))
        localObject2 = TextFormat.getInstance();
      if (localObject3 instanceof Blob)
        localObject3 = dealWithValue4Blob(localObject3);
      if (localObject3 instanceof BinaryObject)
        localObject3 = dealBinaryObject(localObject3);
      if (localObject3 instanceof Clob)
        localObject3 = dealClobValue(localObject3);
      try
      {
        this.resTag.attr("cv", CodeUtils.jsonEncode(CodeUtils.object2JSONable(localObject3)));
      }
      catch (JSONException localJSONException2)
      {
        FRContext.getLogger().log(Level.WARNING, localJSONException2.getMessage(), localJSONException2);
      }
      if (this.cellGUIAttr.isPreviewContent())
        if (localObject3 instanceof ChartPainter)
        {
          HTMLWriterUtils.value2PaintableTag(localObject3, paramCellElement.getStyle(), this.cellWidth, this.cellHeight, localTag, this.repo, false);
          localStyle = localStyle.derivePadding(0, 0);
        }
        else if ((localStyle.getVerticalText() == 1) || (localObject3 instanceof Image) || (localObject3 instanceof Painter))
        {
          this.repo.writeTagBackground(localTag, CellUtils.value2Image(localObject3, localStyle, this.cellWidth, this.cellHeight));
          localStyle = localStyle.derivePadding(0, 0);
        }
        else if ((this.cellHeight > 0) && (this.cellWidth > 0))
        {
          String str = PaintUtils.valueToText(localObject3, (Format)localObject2);
          if (!(this.cellGUIAttr.isShowAsHTML()))
            str = CodeUtils.htmlEncode(str);
          localTag.sub(new TextHtml(str));
        }
    }
    if (localObject2 instanceof SimpleDateFormat)
      this.resTag.attr("fmt", "D" + ((SimpleDateFormat)localObject2).toPattern().trim());
    else if (localObject2 instanceof DecimalFormat)
      this.resTag.attr("fmt", ((DecimalFormat)localObject2).toPattern().trim());
    else if (localObject2 == TextFormat.getInstance())
      this.resTag.attr("fmt", "T");
    if (!(this.cellGUIAttr.isPreviewContent()))
    {
      this.resTag.cls("cehide");
      return this.resTag;
    }
    if ((paramReportGetter.getRowHeight(paramCellElement.getRow()) != 0) && (paramReportGetter.getColumnWidth(paramCellElement.getColumn()) != 0))
      HTMLWriterUtils.style_background2css(localStyle, this.resTag, this.cellGUIAttr, new CellBackgroundDimension(paramCellElement, paramReportGetter), this.repo);
    return ((Tag)(Tag)this.resTag);
  }
}